package com.vhuomai.product.home.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Scope;
import com.vhuomai.mybatis.mapper.page.Page;
import com.vhuomai.product.entity.BaseProduct;
import com.vhuomai.product.home.dto.HomeProductChoose;
import com.vhuomai.product.home.dto.HomeProductInfo;
import com.vhuomai.product.home.dto.HomeProductReq;
import com.vhuomai.product.home.service.HomeProductService;
import com.vhuomai.system.constant.UserRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Cui
 */
@Api(tags = "首页目录-产品关联")
@RestController
@RequestMapping("/api")
@Scope(role = UserRole.MANAGER)
public class HomeProductController {
    @Autowired
    private HomeProductService homeProductService;

    @ApiOperation(value = "设置首页目录产品(支持批量)")
    @PostMapping(value = "/home/product", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> createHomeProduct(@RequestBody HomeProductReq request) {
        homeProductService.createHomeProduct(request);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "取消首页目录产品(支持批量)")
    @PutMapping(value = "/home/product", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> deleteHomeProduct(@RequestBody List<Integer> ids) {
        homeProductService.deleteHomeProduct(ids);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "首页产品基本信息")
    @GetMapping(value = "/home/product", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<List<HomeProductInfo>> homeProductDetail(@RequestParam("homeCategoryId") Integer homeCategoryId) {
        return ServiceResult.success(homeProductService.homeProductDetail(homeCategoryId));
    }

    @ApiOperation(value = "首页产品选择列表")
    @PostMapping(value = "/home/product/choose", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Page<BaseProduct>> homeProductChoose(@RequestBody HomeProductChoose request){
        return ServiceResult.success(homeProductService.homeProductChoose(request));
    }
}
